<?php
include_once( 'cube/controller.php' );

		$oOmsData =& createObject( "odal", "OmsData", "core/data/OmsData" );
		$oOmsData->setConnection( "odalneu", true );
		$oOmsMetaData =& createObject( "odal", "OMSMetaData", "core/meta/OMSMetaData" );
		$oOmsData->setOmsMetaData( $oOmsMetaData ); 

//		$oOmsData2 =& createObject( "odal", "OmsData", "core/data/OmsData" );
//		$oOmsData2->setConnection( "odalneu", true );
//		$oOmsMetaData2 =& createObject( "odal", "OMSMetaData", "core/meta/OMSMetaData" );
//		$oOmsData2->setOmsMetaData( $oOmsMetaData2 ); 
//	$oOmsStructure = &$oOmsData->getOmsStructureByWhere( "elm_scm_id in (2,3,4,5,6,7) and svl_den_id in (2,3)", 0, false );
//	$where = "elm_bookmark like 'prmg%' or elm_scm_id in (9,10,11,12)";
//	$where = "1=1";
//	$oOmsStructure = &$oOmsData->getOmsStructureByWhere( $where, 0, true );
	
	$aWhere["wherestr"] = "elm_id <3";
//	$aWhere["wherestr"] = "elm_id in (12,17,14)";
//	$aWhere2["wherestr"] = "elm_id in (17,14)";
	$aWhere["wherestr"] = "elm_scm_id in (24,22,21)";
//	$aWhere["svlwherestr"] = "and svl_den_id in (2,4)";
//	$aWhere["wherestr"] = "elm_id = 154";
//	$aWhere["wherestr"] = "elm_scm_id in (17,23)";
	//$aWhere["asswherestr"] = "elm_scm_id in (2,3,4,5,6)";
//	$aWhere["wherestr"] = "elm_scm_id in (7)";
	//$aWhere["svlwherestr"] = "and svl_den_id in (2,4)";
	$oOmsStructure = &$oOmsData->getOmsStructureByWhere( $aWhere , 0, 1, false );
//	$oOmsStructure2 = &$oOmsData->getOmsStructureByWhere( $aWhere2 , 0, 1, false );
//	$aWhere["wherestr"] = "elm_scm_id in (21)";
//	$oOmsStructure2 = &$oOmsData2->getOmsStructureByWhere( $aWhere , 0, false );
	//$oOmsStructure = &$oOmsData->getOmsStructureByWhere( "elm_id = 1", 0, false );
	//$oOmsStructure = &$oOmsData->getOmsStructureByWhere( "elm_id = 1", 0, false );

	//incorporate Structure
//	$oOmsStructure->incorporateStructure( $oOmsMetaData, $oOmsStructure2, true );
//	$oOmsStructure->incorporateStructure( $oOmsMetaData, $oOmsStructure2, false );

	//new SimpleValue
//	$oNsp =& $oOmsMetaData->getNamespaceByName( "sample_shop", false );
//	$oDat =& $oNsp->getDatatypeByName( "shop default" );
//	$newelm->createValue( $oDat->getDatatypeEnumerationByName( "default" ), $scheme->getSimpleAttributeById( 5 ), 15 );

	//new Element
//	$scheme =& $oOmsMetaData->getSchemeByName( 'Property',  '/omscube/system', $oOmsData );
//	$newelm =& $oOmsStructure->createElementByScheme( $scheme );
//	$newelm->setDisplayName( "neue Property" );

	//append Element
//	$parent =& $oOmsStructure->getElementById( 14 );
//	$oSchemeParent =& $parent->getScheme();
//	$oComplexAttribute =& $oSchemeParent->getComplexAttributeById( 7 );
//	$parent->append( $newelm, $oComplexAttribute );

	//new Association
//	$elmPropertyDefinition =& $oOmsStructure->getElementById( 12 );
//	$scheme =& $newelm->getScheme();
//	$oCat =& $scheme->getComplexAttributeById( 15 );
//	$newelm->associate( $elmPropertyDefinition, $oCat, true );

//	$success = $oOmsData->saveOmsStructure( $oOmsStructure, true, true );

	//new Element
//	unset( $scheme );
//	unset( $newelm );
//	$scheme =& $oOmsMetaData->getSchemeByName( 'Property',  '/omscube/system', $oOmsData );
//	$newelm =& $oOmsStructure->createElementByScheme( $scheme );
//	$newelm->setDisplayName( "neue Property2" );

	//append Element
//	$parent->append( $newelm, $oComplexAttribute );

	//new Association
//	$newelm->associate( $elmPropertyDefinition, $oCat, true );
//
//	echo "<br><br> ############# PROPERTY 2 <br>";
//	$success = $oOmsData->saveOmsStructure( $oOmsStructure, true, true );

	//delete Subelement
//	$element =& $oOmsStructure->getElementById( 38, false );
//	$oOmsStructure->deleteElement( $element, false );
//	unset( $element );
//	$element =& $oOmsStructure->getElementById( 39, false );
//	$oOmsStructure->deleteElement( $element, false );

	//delete whole shop
//	unset( $element );
//	$element =& $oOmsStructure->getElementById( 2 );
//	$oOmsStructure->deleteElement( $element );
	
	//delete newly created element
//	unset( $element );
//	$element =& $oOmsStructure->getElementById( "new_1" );
//	$oOmsStructure->deleteElement( $element );

//$oOmsStructure->incorporateStructure( $oOmsMetaData, $oOmsStructure2, false );	
	//delete Association
//	unset( $element );
//	unset( $scheme );
//	$element =& $oOmsStructure->getElementById( 11 );
//	$scheme =& $element->getScheme();
//	$oOmsStructure->deleteElement( $element );
//	$element->deleteAssociation( $oOmsStructure->getElementById( 8 ), $scheme->getComplexAttributeByName( "ass_order2product" ), false );

	//delete Value
//	unset( $element );
//	$element =& $oOmsStructure->getElementById( 11 );
//	$value =& $element->getValueByIdAndType( 18, "s", false );
//	$element->deleteValue( $value );
	

	//move Element in Association
//	$source =& $oOmsStructure->getElementById( 177 );
//	$scheme =& $source->getScheme();
//	$oCat =& $scheme->getComplexAttributeById( 28 );
//	$element =& $oOmsStructure->getElementById( 178 );
//	$beforeElement =& $oOmsStructure->getElementById( 179 );
//	$source->moveElementBefore( $oCat, $element, $beforeElement );
	
	//move append Element in Association
	$source =& $oOmsStructure->getElementById( 177 );
	$scheme =& $source->getScheme();
	$oCat =& $scheme->getComplexAttributeById( 28 );
	$element =& $oOmsStructure->getElementById( 180 );
	$source->moveElementAppend( $oCat, $element );

	//save Changes
	$success = $oOmsData->saveOmsStructure( $oOmsStructure, true );

	//output structure as xml
	$xml = $oOmsStructure->createXMLDoc( $oOmsMetaData, false );
	echo $xml;
	
//	$oElement =& $oOmsStructure->getElementById( 10 );
//	$oScheme =& $oElement->getScheme();
////	print_r( $oScheme );
//	$oComplexAttribute =& $oScheme->getComplexAttributeByName( "objects");
////	print_r( $oComplexAttribute );
//	$childs =& $oElement->getChildElements( $oComplexAttribute );
//	echo count( $childs );
?>